package com.rtx.common;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.servlet.http.HttpServletRequest;

public class HttpServletRequestUtil {

	/**
	 * 获取http请求体
	 * @param request
	 * @return
	 */
	public static String getHttpBody(HttpServletRequest request){
		InputStream in = null;
		BufferedReader br = null;
		StringBuffer buffer = new StringBuffer();
		try {
			in = request.getInputStream();
			br = new BufferedReader(new InputStreamReader(in, "UTF-8"));		
			String s = br.readLine();
			while(s!=null){
				buffer.append(s);
				s=br.readLine();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			try {
				if(in != null)
				in.close();
				if(br != null)
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return buffer.toString();
	}
}
